package com.springcloud.alibaba.stream.service.impl;


import com.springcloud.alibaba.stream.service.MessageService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;

import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;


import javax.annotation.Resource;
import java.util.UUID;


/**
 * @Author:RenPu
 * @Date: 2020/7/2 10:34
 * @Version: 1.0
 * @description:
 */

@EnableBinding(Source.class)  //定义消息来源
public class MessageServiceImpl implements MessageService {


    @Resource
    @Qualifier
    private MessageChannel messageChannel;  //消息发送管道


    @Override
    public String send() {

        String serial = UUID.randomUUID().toString();
        messageChannel.send( MessageBuilder.withPayload(serial).build() );
        System.out.println("*************有消息了O(∩_∩)O哈哈~,流水号为："+serial );

        return null;
    }
}
